package com.dearbinge.opentapi.content.defrayStream;

import com.baomidou.mybatisplus.plugins.Page;
import com.dearbinge.data.api.defrayStream.DefrayStreamService;
import com.dearbinge.data.pojo.defrayStream.DefrayStream;
import com.dearbinge.utils.ResultMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(description = "支付流水")
@RestController
@RequestMapping("/defrayStream")
@EnableAutoConfiguration
public class DefrayStreamController {

    @Autowired
    private DefrayStreamService defrayStreamService;

    /**
     * 新增/修改
     */
    @ApiOperation(value = "新增/修改",notes = "新增/修改",produces = "query")
    @RequestMapping(value = "addOrUpdate",method = RequestMethod.POST)
    public ResultMsg<String> addOrUpdate(@RequestBody DefrayStream defrayStream){
        try {
            Integer dataCode = 0;
            if (defrayStream.getId() != null && defrayStream.getId() != 0){
                dataCode = defrayStreamService.update(defrayStream);
                if (dataCode > 0){
                    return ResultMsg.ok("修改成功");
                }
            }else {
                dataCode = defrayStreamService.insert(defrayStream);
                if (dataCode > 0){
                    return ResultMsg.ok("新增成功");
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultMsg.error(500,"系统异常");
    }

    /**
     * 根据ID删除
     */
    @ApiOperation(value = "根据ID删除",notes = "根据ID删除")
    @ApiImplicitParam(name = "id",value = "id",paramType = "query")
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public ResultMsg<String> delete(Integer id){
        try {
            Integer dataCode = defrayStreamService.delete(id);
            if (dataCode > 0){
                return ResultMsg.ok("删除成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultMsg.error(500,"系统异常");
    }

    /**
     * 根据用户ID查询
     */
    @ApiOperation(value = "根据用户ID查询",notes = "根据用户ID查询")
    @ApiImplicitParams({@ApiImplicitParam(name = "userid",value = "用户ID",paramType = "query")
            ,@ApiImplicitParam(name = "pageNo",value = "当前页",paramType = "query")
            ,@ApiImplicitParam(name = "pageSize",value = "页面数量",paramType = "query")})
    @RequestMapping(value = "/getByUserIdPage",method = RequestMethod.GET)
    public ResultMsg<Page> getByUserIdPage(String userId,Integer pageNo,Integer pageSize){
        try {
            Page page = defrayStreamService.getByUserIdPage(userId,pageNo,pageSize);
            return ResultMsg.ok(page);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultMsg.error(500,"系统异常");
    }
}
